﻿<UserControl x:Class="Samba.Presentation.Terminal.MenuItemSelectorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:FxButton="clr-namespace:FlexButton;assembly=FlexButton"
             xmlns:Common="clr-namespace:Samba.Presentation.Common;assembly=Samba.Presentation.Common" mc:Ignorable="d" 
             d:DesignHeight="320" d:DesignWidth="240" Loaded="UserControl_Loaded">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ItemsControl MaxHeight="70" Grid.Row="0" ItemsSource="{Binding MostUsedMenuItems}" >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Rows="1" Columns="{Binding MostUsedItemsCategory.ColumnCount}" Height="{Binding MostUsedItemsCategory.ButtonHeight}"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <FxButton:FlexButton 
                            Margin="0,0,0,0"
                            Focusable="False"
                            ButtonColor="{Binding ButtonColor}"
                            ButtonImage="{Binding ImagePath}"
                            Content="{Binding Caption}"
                            Command="{Binding Command}" 
                            CommandParameter="{Binding ScreenMenuItem}"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>


        <Grid Name="MainGrid" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="35*"/>
                <ColumnDefinition Width="65*"/>
            </Grid.ColumnDefinitions>

            <ScrollViewer Grid.Column="0" Common:KineticBehaviour.HandleKineticScrolling="True" Margin="0,0,2,0" VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding Categories}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <FxButton:FlexButton Content="{Binding Caption}" 
                                                Focusable="False"
                                                Command="{Binding ButtonCommand}" 
                                                CommandParameter="{Binding Category}"
                                                Height="{Binding MButtonHeight}"
                                                Margin="0,0,0,-1"
                                                CornerRadius="0"
                                                ButtonImage="{Binding ImagePath}"
                                                ButtonColor="{Binding MButtonColor}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>

            <Grid Grid.Column="1" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="25*"/>
                    <RowDefinition Height="75*"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <ScrollViewer Grid.Row="0" Name="Scroller">
                    <ItemsControl VerticalAlignment="Stretch" ItemsSource="{Binding AddedMenuItems}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Button Focusable="False" 
                                    Style="{StaticResource ItemsControlButtonStyle}"
                                            Command="{Binding DataContext.ItemSelectedCommand,RelativeSource={RelativeSource AncestorType=ItemsControl,Mode=FindAncestor}}"
                                            CommandParameter="{Binding}">
                                    <Grid>
                                        <StackPanel>
                                            <Grid Background="{Binding Background}" Margin="-1">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>

                                                <TextBlock FontWeight="{Binding FontWeight}" TextDecorations="{Binding TextDecoration}" Padding="1" Foreground="{Binding Foreground}" Grid.Column="0" Text="{Binding Quantity,StringFormat='#.##'}" Margin="5,1,6,1"/>
                                                <TextBlock FontWeight="{Binding FontWeight}" TextDecorations="{Binding TextDecoration}" Padding="1" Foreground="{Binding Foreground}" Grid.Column="1" Text="{Binding Description}" TextTrimming="CharacterEllipsis" Margin="1"/>
                                            </Grid>

                                            <ItemsControl ItemsSource="{Binding Properties}">
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Grid>
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="*"/>
                                                                <ColumnDefinition Width="auto"/>
                                                            </Grid.ColumnDefinitions>
                                                            <TextBlock Grid.Column="0" Foreground="DarkBlue" FontWeight="Bold" Text="{Binding DisplayString}" Margin="30,0,0,0" />
                                                            <TextBlock Grid.Column="1" Foreground="DarkBlue" FontWeight="Bold" Text="{Binding PriceString}" Padding="1" HorizontalAlignment="Right"/>
                                                        </Grid>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </StackPanel>
                                    </Grid>
                                </Button>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>

                <Grid Grid.Row="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <ListBox Grid.Row="0" BorderThickness="0" Background="Transparent"
                            Visibility="{Binding IsQuickNumeratorVisible,Converter={StaticResource VisibilityConverter}}"
                            ItemsSource="{Binding QuickNumeratorValues}" SelectedItem="{Binding NumeratorValue,Mode=TwoWay}">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Rows="1"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Viewbox>
                                        <TextBlock Name="Label" Text="{Binding}"/>
                                    </Viewbox>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <ListBox.Resources>
                            <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
                            <Style TargetType="ListBoxItem">
                                <Setter Property="SnapsToDevicePixels" Value="true"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <Border Margin="0,0,1,1" Background="WhiteSmoke" Name="Border" BorderThickness="1" CornerRadius="2" BorderBrush="Gray">
                                                <ContentPresenter />
                                            </Border>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsSelected" Value="true">
                                                    <Setter Property="FontWeight" Value="Bold"/>
                                                    <Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                                                    <Setter TargetName="Border" Property="Background" Value="{StaticResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                                </Trigger>
                                                <Trigger Property="IsEnabled" Value="false">
                                                    <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.Resources>
                    </ListBox>

                    <ScrollViewer Grid.Row="1" Common:KineticBehaviour.HandleKineticScrolling="True" VerticalScrollBarVisibility="Auto">
                        <ItemsControl Margin="1,0,0,0" ItemsSource="{Binding MenuItems}" HorizontalAlignment="Stretch">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid Columns="{Binding SelectedCategory.ColumnCount}" VerticalAlignment="Top"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <FxButton:FlexButton 
                                    Focusable="False"    
                                    SnapsToDevicePixels="True"
                                    ButtonColor="{Binding ButtonColor}"
                                    Content="{Binding Caption}"
                                    Command="{Binding Command}" 
                                    CommandParameter="{Binding ScreenMenuItem}"
                                    Height="{Binding Category.ButtonHeight}"
                                    ButtonImage="{Binding ImagePath}"
                                    Margin="-1,0,0,-1"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                </Grid>

                <UniformGrid Grid.Row="2" Columns="2" Rows="1" Visibility="{Binding IsPageNumberNavigatorVisible,Converter={StaticResource VisibilityConverter}}">
                    <FxButton:FlexButton Margin="0,3,3,3" Command="{Binding DecPageNumberCommand}" Content="{Binding DecPageNumberCommand.Caption}"/>
                    <FxButton:FlexButton Margin="0,3,0,3" Command="{Binding IncPageNumberCommand}" Content="{Binding IncPageNumberCommand.Caption}"/>
                </UniformGrid>

            </Grid>
        </Grid>
    </Grid>
</UserControl>
